##############################################################################
# CMake
##############################################################################

cmake_minimum_required(VERSION 2.8.0)
project(qt_plane)


set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

##############################################################################
# Catkin
##############################################################################

# qt_build provides the qt cmake glue, roscpp the comms for a default talker
#find_package(catkin REQUIRED COMPONENTS qt_build roscpp)
find_package(PkgConfig REQUIRED)
find_package(Qt5 REQUIRED Core Widgets Quick Gui QuickWidgets Multimedia MultimediaWidgets )
find_package(OpenCV REQUIRED)
# find_package(CUDA REQUIRED)
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  message_generation
  dynamixel_sdk_examples
  epos_msgs
  cv_bridge
)

set(QT_LIBRARIES Qt5::Widgets Qt5::Gui Qt5::Core Qt5::Quick Qt5::QuickWidgets Qt5::Multimedia Qt5::MultimediaWidgets)

include_directories(include ${catkin_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR} ${SISL_INCLUDE_DIR} /usr/include/opencv4)

pkg_search_module(GST1 REQUIRED gstreamer-1.0)
set(CMAKE_C_STANDARD 99)
include_directories(/usr/include/gstreamer-1.0/gst)

#zanglnag
include_directories(/usr/include/x86_64-linux-gnu)

# Use this to define what the package will export (e.g. libs, headers).
# Since the default here is to produce only a binary, we don't worry about
# exporting anything. 

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES qt_plane
   CATKIN_DEPENDS roscpp rospy std_msgs dynamixel_sdk_examples epos_msgs
#  DEPENDS system_lib
)


##############################################################################
# Qt Environment
##############################################################################

# this comes from qt_build's qt-ros.cmake which is automatically 
# included via the dependency call in package.xml
# Add the appropriate components to the component list here

##############################################################################
# Sections
##############################################################################

file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/*.hpp *.h)

QT5_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT5_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT5_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

##############################################################################
# Sources
##############################################################################

file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)

##############################################################################
# Binaries
##############################################################################

add_executable(main src/main.cpp ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP} )

target_link_libraries(main ${QT_LIBRARIES} ${catkin_LIBRARIES} /usr/local/lib/libsisl.a ${OpenCV_LIBS})

target_include_directories(main PRIVATE ${GST1_INCLUDE_DIRS})
target_link_libraries(main ${GST1_LIBRARIES})

#zanglang
find_library(AVCODEC_LIBRARY avcodec)
find_library(AVFORMAT_LIBRARY avformat)
find_library(SWSCALE_LIBRARY swscale)
find_library(AVDEVICE_LIBRARY avdevice)
find_library(AVUTIL_LIBRARY avutil)
target_link_libraries(main ${AVCODEC_LIBRARY} ${AVFORMAT_LIBRARY} ${SWSCALE_LIBRARY} ${AVDEVICE_LIBRARY} ${AVUTIL_LIBRARY})

install(TARGETS main RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})


